package com.tjn.set_;

import java.util.HashSet;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class HashSetSource02 {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        //HashSet扩容机制调试：
        HashSet hashSet = new HashSet();
        for(int i = 1; i <= 100; i++) {
            hashSet.add(i);//1,2,3,4,5...100
        }

        //我现在要控制不管元素是什么都让它添加到一条链表上
        HashSet hashSet1 = new HashSet();
        for (int i = 0; i <= 9; i++) {
            hashSet1.add(new A(i));
        }

        //不管是添加元素到哪个链表上，只要添加了结点，那么底层代码中size就会++，
        //所以不管添加结点在哪个链表上面，只要添加结点超过12，就会扩容
        HashSet hashSet2 = new HashSet();
        for (int i = 0; i <= 7; i++) {
            hashSet2.add(new B(i));
        }
        for (int i = 0; i <= 7; i++) {
            hashSet2.add(new C(i));
        }
    }
}

class A{
    private int n;
    public A(int n) {
        this.n = n;
    }

    @Override
    public int hashCode() {
        return 100;
    }
}

class B{
    private int n;
    public B(int n) {
        this.n = n;
    }
    @Override
    public int hashCode() {
        return 200;
    }
}

class C{
    private int n;
    public C(int n) {
        this.n = n;
    }
    @Override
    public int hashCode() {
        return 300;
    }
}